package com.zxy.lm.controller;

import com.zxy.lm.entity.Book;
import com.zxy.lm.service.BookService;
import com.zxy.lm.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

/**
 * @ClassName AdminPageController
 * @Author 14995
 * @Date 2021-6-22 21:10
 * @Version 1.0
 */
@Controller
@RequestMapping("/admin")
public class AdminPageController {

    @Autowired
    private BookService bookService;

    @Autowired
    private TypeService typeService;

    @GetMapping("/login")
    public String login() {
        return "admin/login";
    }

    @GetMapping("/navLeft")
    public String navLeft() {
        return "admin/navLeft";
    }

    @GetMapping("/nav")
    public String nav() {
        return "admin/nav";
    }

    @GetMapping("/queryBook")
    public String queryBook(Model model) {
        List<Book> list = bookService.queryAllBook();
        Map<Integer, String> map = typeService.queryMapAllType();
        model.addAttribute("bookList", list);
        model.addAttribute("typeMap", map);
        return "admin/queryBook";
    }

    @GetMapping("/editBook")
    public String editBook(Model model, Integer bookId) {
        Book book = bookService.queryById(bookId);
        Map<Integer, String> map = typeService.queryMapAllType();
        model.addAttribute("editBook", book);
        model.addAttribute("typeMap", map);
        return "admin/editBook";
    }

    @GetMapping("/addBook")
    public String addBook(Model model) {
        Map<Integer, String> map = typeService.queryMapAllType();
        model.addAttribute("typeMap", map);
        return "admin/addBook";
    }

    @GetMapping("/borrowBook")
    public String borrow() {
        return "admin/borrowBook";
    }

    @GetMapping("/queryReturnBook")
    public String queryReturnBook() {
        return "admin/queryReturnBook";
    }

    @GetMapping("/releaseAnnouncement")
    public String releaseAnnouncement() {
        return "admin/releaseAnnouncement";
    }
}
